import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:timesdk_plugin/timesdk_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    initTimeSdk();
  }

  void initTimeSdk() async {
    try {
      TimesdkPlugin.initTimeSDK();
    } catch (e) {
      print("init timeSdk error: " + e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              // GestureDetector(
              //   onTap: () {
              //     TimesdkPlugin.initTimeSDK();
              //   },
              //   child: const Text("Init SDK"),
              // ),
              GestureDetector(
                onTap: () {
                  TimesdkPlugin.checkSdkPermission();
                },
                child: const Text("Check Permission"),
              ),
              GestureDetector(
                onTap: () {
                  var data = jsonEncode({
                    "name": "111",
                  });
                  TimesdkPlugin.collectMessage(data);
                },
                child: const Text("Collect Message"),
              )
            ],
          ),
        ),
      ),
    );
  }
}
